home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-17 | 14.1 KB | 562 lines | [TEXT/MMCC] |
- /*
- File: GXToolWindow.cp
-
- Contains: A palette window that will show info about the current shape
-
- Written by: Jon Summers
-
- Copyright: © 1994 by Jon Summers, all rights reserved.
-
- Change History (most recent first):
-
- */
-
- #include "GXToolWindow.h"
-
- static long gToolPage = 0;
- static long gToolNumPages = 0;
- static gxShape gToolPageShape = nil;
- static gxShape gToolTestShape = nil;
-
- gxShape GetInspectShape(InspectShapeType theType);
- gxShape GetInspectShape(InspectShapeType theType)
- {
- switch (theType)
- {
- case ePageShape : return gToolPageShape;
- case eTestShape : return gToolTestShape;
- }
- return nil;
- }
-
- TGXToolWindow* TGXToolWindow::fgToolWindow = nil;
-
- TGXToolWindow::TGXToolWindow()
- : TToolWindow(1028)
- {
- fgToolWindow = this;
- }
-
- TGXToolWindow::~TGXToolWindow()
- {
- fgToolWindow = nil;
- }
-
- #define kShapeTypeStrList 1000
- #define kShapeAttributeStrList 1001
- #define kShapePartStrList 1002
- #define kShapeFillStrList 1003
-
- #define AppendChar(s, c) s[++(*s)] = c
- #define AppendComma(s) AppendChar(s,',')
- #define AppendSpace(s) AppendChar(s,' ')
-
- void PrintListIndex(Str31 theStr, short theStrList, short theIndex);
- void PrintListIndex(Str31 theStr, short theStrList, short theIndex)
- {
- if (*theStr)
- {
- *theStr = 0;
- AppendComma(theStr);
- AppendSpace(theStr);
- DrawString(theStr);
- }
- GetIndString(theStr, theStrList, theIndex);
- DrawString(theStr);
- }
-
- void PrintShapeAttributes(gxShapeAttribute theShapeAttribute);
- void PrintShapeAttributes(gxShapeAttribute theShapeAttribute)
- {
- Str31 aStr;
- *aStr = 0;
- if (theShapeAttribute == gxNoAttributes)
- PrintListIndex(aStr, kShapeAttributeStrList, 1);
- else
- {
- if (theShapeAttribute & gxDirectShape)
- PrintListIndex(aStr, kShapeAttributeStrList, 2);
- if (theShapeAttribute & gxRemoteShape)
- PrintListIndex(aStr, kShapeAttributeStrList, 3);
- if (theShapeAttribute & gxCachedShape)
- PrintListIndex(aStr, kShapeAttributeStrList, 4);
- if (theShapeAttribute & gxLockedShape)
- PrintListIndex(aStr, kShapeAttributeStrList, 5);
- if (theShapeAttribute & gxGroupShape)
- PrintListIndex(aStr, kShapeAttributeStrList, 6);
- if (theShapeAttribute & gxMapTransformShape)
- PrintListIndex(aStr, kShapeAttributeStrList, 7);
- if (theShapeAttribute & gxUniqueItemsShape)
- PrintListIndex(aStr, kShapeAttributeStrList, 8);
- if (theShapeAttribute & gxIgnorePlatformShape)
- PrintListIndex(aStr, kShapeAttributeStrList, 9);
- if (theShapeAttribute & gxNoMetricsGridShape)
- PrintListIndex(aStr, kShapeAttributeStrList, 10);
- if (theShapeAttribute & gxDiskShape)
- PrintListIndex(aStr, kShapeAttributeStrList, 11);
- if (theShapeAttribute & gxMemoryShape)
- PrintListIndex(aStr, kShapeAttributeStrList, 12);
- }
- }
-
- void PrintGxRect(gxRectangle* pRect);
- void PrintGxRect(gxRectangle* pRect)
- {
- Str31 aStr;
- TextFace(bold);
- *aStr = 0;
- AppendSpace(aStr);
- AppendChar(aStr, '[');
- DrawString(aStr);
- NumToString(pRect->left >> 16, aStr);
- AppendComma(aStr);
- DrawString(aStr);
- NumToString(pRect->top >> 16, aStr);
- AppendComma(aStr);
- DrawString(aStr);
- NumToString(pRect->right >> 16, aStr);
- AppendComma(aStr);
- DrawString(aStr);
- NumToString(pRect->bottom >> 16, aStr);
- AppendChar(aStr, ']');
- DrawString(aStr);
- TextFace(0);
- }
-
- void PrintGxPoint(gxPoint* pPoint);
- void PrintGxPoint(gxPoint* pPoint)
- {
- Str31 aStr;
- TextFace(bold);
- *aStr = 0;
- AppendSpace(aStr);
- AppendChar(aStr, '(');
- DrawString(aStr);
- NumToString(pPoint->x >> 16, aStr);
- AppendComma(aStr);
- DrawString(aStr);
- NumToString(pPoint->y >> 16, aStr);
- AppendChar(aStr, ')');
- DrawString(aStr);
- TextFace(0);
- }
-
- void PrintNumber(long theNumber);
- void PrintNumber(long theNumber)
- {
- Str31 aStr;
- TextFace(bold);
- DrawChar(' ');
- NumToString(theNumber, aStr);
- DrawString(aStr);
- TextFace(0);
- }
-
- void PrintBit(long* pLong, short theIndex);
- void PrintBit(long* pLong, short theIndex)
- {
- long aLong = pLong[theIndex/32];
- short aShift = theIndex%32;
- aShift = 32 - aShift;
- if (aShift)
- aLong >>= aShift;
- DrawChar('0' +(aLong & 0x1));
- }
-
- typedef struct // GXUniv
- {
- union
- {
- gxRectangle rect;
- gxPoint point;
- gxLine line;
- gxCurve curve;
- gxBitmap bitmap;
- } u;
- } GXUniv;
- #define kLineIncrement 12
- short PrintTheShape(gxShape theShape, short theVert, short theHoriz);
- short PrintTheShape(gxShape theShape, short theVert, short theHoriz)
- {
- gxShapeType aShapeType = GXGetShapeType(theShape);
- gxShapeAttribute aShapeAttribute = GXGetShapeAttributes(theShape);
- gxShapeFill aShapeFill = GXGetShapeFill(theShape);
-
- Str63 aStr;
- short aLineStart = theHoriz;
- short aLinePosn = theVert;
- GXUniv aUniv;
- long aSize;
- long aVector;
- long aContour;
-
- (void)GXGetShapeLocalBounds(theShape, &aUniv.u.rect);
-
- aLinePosn += kLineIncrement;
- MoveTo(aLineStart, aLinePosn);
- DrawString("\pType");
- TextFace(bold);
- DrawChar(' ');
- *aStr = 0;
- PrintListIndex(aStr, kShapeTypeStrList, aShapeType);
- TextFace(0);
-
- aLinePosn += kLineIncrement;
- MoveTo(aLineStart, aLinePosn);
- DrawString("\pAttributes");
- TextFace(bold);
- DrawChar(' ');
- PrintShapeAttributes(aShapeAttribute);
- TextFace(0);
-
- aLinePosn += kLineIncrement;
- MoveTo(aLineStart, aLinePosn);
- DrawString("\pBounds");
- PrintGxRect(&aUniv.u.rect);
-
- aLinePosn += kLineIncrement;
- MoveTo(aLineStart, aLinePosn);
- DrawString("\pFill");
- TextFace(bold);
- DrawChar(' ');
- *aStr = 0;
- PrintListIndex(aStr, kShapeFillStrList, aShapeFill+1);
- TextFace(0);
-
- aLinePosn += kLineIncrement;
- MoveTo(aLineStart, aLinePosn);
- switch (aShapeType)
- {
- case gxEmptyType : break;
- case gxPointType :
- DrawString("\pPoint");
- (void)GXGetPoint(theShape, &aUniv.u.point);
- PrintGxPoint(&aUniv.u.point);
- /***struct gxPoint {
- Fixed x;
- Fixed y;
- extern gxPoint *GXGetPoint(gxShape source, gxPoint *data)
- ***/
- break;
- case gxLineType :
- DrawString("\pLine");
- (void)GXGetLine(theShape, &aUniv.u.line);
- TextFace(bold);
- DrawChar(' ');
- DrawString("\pfirst");
- PrintGxPoint(&aUniv.u.line.first);
- TextFace(bold);
- DrawChar(' ');
- DrawString("\plast");
- PrintGxPoint(&aUniv.u.line.last);
- /***struct gxLine {
- struct gxPoint first;
- struct gxPoint last;
- extern gxLine *GXGetLine(gxShape source, gxLine *data)
- ***/
- break;
- case gxCurveType :
- DrawString("\pCurve");
- (void)GXGetCurve(theShape, &aUniv.u.curve);
- TextFace(bold);
- DrawChar(' ');
- DrawString("\pfirst");
- PrintGxPoint(&aUniv.u.curve.first);
- TextFace(bold);
- DrawChar(' ');
- DrawString("\pcontrol");
- PrintGxPoint(&aUniv.u.curve.control);
- TextFace(bold);
- DrawChar(' ');
- DrawString("\plast");
- PrintGxPoint(&aUniv.u.curve.last);
- /*** struct gxCurve {
- struct gxPoint first;
- struct gxPoint control;
- struct gxPoint last;
- extern gxCurve *GXGetCurve(gxShape source, gxCurve *data)
- ***/
- break;
- case gxRectangleType :
- DrawString("\pRect");
- (void)GXGetRectangle(theShape, &aUniv.u.rect);
- PrintGxRect(&aUniv.u.rect);
- /***struct gxRectangle {
- Fixed left;
- Fixed top;
- Fixed right;
- Fixed bottom;
- extern gxRectangle *GXGetRectangle(gxShape source, gxRectangle *data)
- ***/
- break;
- case gxPolygonType :
- DrawString("\pPolygon");
- aSize = GXGetPolygons(theShape, nil);
- // DrawString("\p Size ");
- TextFace(bold);
- // PrintNumber(aSize);
- if (aSize)
- {
- gxPolygons* pPolygonsBlock = (gxPolygons*)NewPtr(aSize);
- if (pPolygonsBlock)
- {
- gxPolygon* pPolygon = pPolygonsBlock->contour;
-
- (void)GXGetPolygons(theShape, pPolygonsBlock);
- TextFace(bold);
- DrawString("\p Contours ");
- PrintNumber(pPolygonsBlock->contours);
- aLineStart += kLineIncrement;
- for (aContour = 0; aContour < pPolygonsBlock->contours; ++aContour)
- {
- aLinePosn += kLineIncrement;
- MoveTo(aLineStart, aLinePosn);
- TextFace(0);
- DrawString("\pVectors ");
- TextFace(bold);
- PrintNumber(pPolygon->vectors);
- TextFace(bold);
- for (aVector = 0; aVector < pPolygon->vectors; ++aVector)
- PrintGxPoint(&pPolygon->vector[aVector]);
- pPolygon = (gxPolygon*)&pPolygon->vector[pPolygon->vectors];
- }
- DisposePtr((Ptr)pPolygonsBlock);
- }
- }
- /***struct gxPolygon {
- long vectors;
- struct gxPoint vector[1];
- struct gxPolygons {
- long contours;
- struct gxPolygon contour[1];
- extern long GXGetPolygons(gxShape source, gxPolygons *data)
- extern gxPolygon *GetPolygon(gxShape source, long contour, gxPolygon *polygon);
- ***/
- break;
- case gxPathType :
- DrawString("\pPath");
- aSize = GXGetPaths(theShape, nil);
- DrawString("\p Size ");
- TextFace(bold);
- PrintNumber(aSize);
- if (aSize)
- {
- gxPaths* pPathsBlock = (gxPaths*)NewPtr(aSize);
- if (pPathsBlock)
- {
- gxPath* pPath = &pPathsBlock->contour[0];;
- (void) GXGetPaths(theShape, pPathsBlock);
-
- TextFace(bold);
- DrawString("\p Contours ");
- PrintNumber(pPathsBlock->contours);
- aLineStart += kLineIncrement;
- for (aContour = 0; aContour < pPathsBlock->contours; ++aContour)
- {
- long* pControl = pPath->controlBits;
- gxPoint* pVector;
-
- aSize = pPath->vectors+31;
- aSize /= 32;
- aSize *= sizeof(long); // num of longs needed for control bits
- pVector = (gxPoint*)(((Ptr)pControl) + aSize); // skip controlBits
-
- aLinePosn += kLineIncrement;
- MoveTo(aLineStart, aLinePosn);
- TextFace(0);
- DrawString("\pVectors ");
- TextFace(bold);
- PrintNumber(pPath->vectors);
- for (aVector = 0; aVector < pPath->vectors; ++aVector)
- {
- TextFace(bold);
- PrintGxPoint(&pVector[aVector]);
- TextFace(0);
- PrintBit(pControl, aVector);
- if (pPath->vectors > 5)
- if (aVector == 4)
- {
- DrawChar('…');
- aVector = pPath->vectors-2; // force draw last
- }
- }
- pPath = (gxPath*)&pVector[pPath->vectors];
- }
- DisposePtr((Ptr)pPathsBlock);
- }
- }
- /***struct gxPath {
- long vectors;
- long controlBits[1];
- struct gxPoint vector[1];
- struct gxPaths {
- long contours;
- struct gxPath contour[1];
- extern long GXGetPaths(gxShape source, gxPaths *data)
- extern gxPath *GetPath(gxShape source, long contour, gxPath *path);
- ***/
- break;
- case gxBitmapType :
- DrawString("\pBitmap");
- (void)GXGetBitmap(theShape, &aUniv.u.bitmap, nil);
- aLinePosn += kLineIncrement;
- MoveTo(aLineStart, aLinePosn);
- TextFace(0);
- DrawString("\p width ");
- TextFace(bold);
- PrintNumber(aUniv.u.bitmap.width);
- TextFace(0);
- DrawString("\p height ");
- TextFace(bold);
- PrintNumber(aUniv.u.bitmap.height);
- TextFace(0);
- DrawString("\p rowBytes ");
- TextFace(bold);
- PrintNumber(aUniv.u.bitmap.rowBytes);
- TextFace(0);
- DrawString("\p pixelSize ");
- TextFace(bold);
- PrintNumber(aUniv.u.bitmap.pixelSize);
- TextFace(0);
- /***struct gxBitmap {
- char *image;
- long width;
- long height;
- long rowBytes;
- long pixelSize;
- gxColorSpace space;
- gxColorSet set;
- gxColorProfile profile;
- extern gxBitmap *GXGetBitmap(gxShape source, gxBitmap *data, gxPoint *position)
- ***/
- break;
- case gxTextType :
- DrawString("\pText");
- aSize = GXGetText(theShape, nil, nil, nil);
- TextFace(0);
- DrawString("\p length ");
- TextFace(bold);
- PrintNumber(aSize);
- TextFace(0);
- if (aSize)
- {
- if (aSize > 60)
- aSize = 60;
- (void)GXGetText(theShape, nil, &aStr[2], nil);
- aStr[1] = ' ';
- *aStr = aSize+1;
- aLineStart += kLineIncrement;
- aLinePosn += kLineIncrement;
- MoveTo(aLineStart, aLinePosn);
- TextFace(bold);
- DrawString(aStr);
- TextFace(0);
- }
- /***
- extern long GXGetText(gxShape source, long *charCount, unsigned char text[], gxPoint *position)
- extern gxFont GXFindFont(gxFontStorageTag storage, gxFontStorageReference reference, gxFontAttribute *attributes)
- extern long GXFindFontName(gxFont fontID, gxFontName name, gxFontPlatform platform, gxFontScript script, gxFontLanguage language, unsigned char text[], long *index)
- extern gxFont GXGetShapeFont(gxShape source)
- extern Fixed GXGetShapeTextSize(gxShape source)
- extern fract GXGetShapeJustification(gxShape source)
- extern long GXGetShapeFace(gxShape source, gxTextFace *face)
- ***/
- break;
- case gxGlyphType :
- DrawString("\pGlyph");
- /***
- extern long GXGetGlyphs(gxShape source, long *charCount, unsigned char text[], gxPoint positions[], long advance[],
- gxPoint tangents[], long *runCount, short styleRuns[], gxStyle glyphStyles[])
- ***/
- break;
- case gxLayoutType :
- DrawString("\pLayout");
- /***
- extern long GXGetLayout(gxShape layout, void *text, long *styleRunCount, short styleRunLengths[], gxStyle styles[],
- long *levelRunCount, short levelRunLengths[], short levels[], gxLayoutOptions *layoutOptions, gxPoint *position);
- ***/
- break;
- case gxFullType : break;
- case gxPictureType :
- /***
- extern long GXGetPicture(gxShape source, gxShape shapes[], gxStyle styles[], gxInk inks[], gxTransform transforms[])
- ***/
- break;
- }
- return aLinePosn;
- }
-
- void TGXToolWindow::Draw(void)
- {
- CSavePort aSavePort(fWindow);
- gxShape aInspectShape = GetInspectShape(ePageShape);
- short aLineStart = 4;
- short aLinePosn = 2;
-
- TextFont(geneva);
- TextSize(9);
-
- EraseRect(&fWindow->portRect);
-
- aLinePosn += kLineIncrement;
- MoveTo(aLineStart, aLinePosn);
- TextFace(bold);
- DrawString("\pPage: ");
- TextFace(0);
-
- if (aInspectShape)
- {
- TextFace(bold);
- PrintNumber(gToolPage);
- TextFace(0);
- DrawString("\p of ");
- TextFace(bold);
- PrintNumber(gToolNumPages);
- TextFace(0);
-
- aLinePosn = PrintTheShape(aInspectShape, aLinePosn, aLineStart+kLineIncrement);
-
- aInspectShape = GetInspectShape(eTestShape);
- aLinePosn += kLineIncrement;
- MoveTo(aLineStart, aLinePosn);
- TextFace(bold);
- DrawString("\pAt: ");
- TextFace(0);
- if (aInspectShape)
- aLinePosn = PrintTheShape(aInspectShape, aLinePosn, aLineStart+kLineIncrement);
- else
- DrawString("\pnone");
- }
- else
- DrawString("\pnone");
- }
-
- void SetInspectPage(long thePageNum, long theNumOfPages)
- {
- gToolPage = thePageNum;
- gToolNumPages = theNumOfPages;
- }
-
- void SetInspectShape(InspectShapeType theType, gxShape theShape)
- {
- switch (theType)
- {
- case ePageShape :
- if (gToolPageShape == theShape)
- return;
- gToolPageShape = theShape;
- gToolTestShape = nil;
- break;
- case eTestShape :
- if (gToolTestShape == theShape)
- return;
- gToolTestShape = theShape;
- break;
- default :
- return;
- }
- if (TGXToolWindow::fgToolWindow)
- TGXToolWindow::fgToolWindow->Draw();
- }
-
-